<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt' %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>订单页面</title>
</head>

<script type="text/javascript">
var deleteOrder = false;
var deleteOrderid = 0;

$(function(){
	$("a[orderStatus]").click(function(){
		var orderStatus = $(this).attr("orderStatus");
		if('all' == orderStatus){
			$("table[orderStatus").show();
		}else{
			$("table[orderStatus]").hide();
			$("table[orderStatus="+orderStatus+"]").show();
		}
		
		$("div.orderType div").removeClass("selectedOrderType");
		$(this).parent("div").addClass("selectedOrderType");
	});
	$("a.deleteOrderLink").click(function(){
		deleteOrderid = $(this).attr("oid");
		deleteOrder = false;
		$("#deleteConfirmModal").modal("show");
	});
	
	$("button.deleteConfirmButton").click(function(){
		deleteOrder = true;
		$("#deleteConfirmModal").modal('hide');
	});
	
	$("#deleteConfirmModal").on('hidden.bs.modal',function(e){
		if(deleteOrder){
			var page = "foredeleteOrder";
			$.post(
					page,
					{"order.id":deleteOrderid},
					function(result){
						if("success" == result){
							$("table.orderListItemTable[oid="+deleteOrderid+"]").hide();
						}else{
							location.href="login.jsp";
						}
					}
				);
		}
	});
	
	$(".ask2delivery").click(function(){
		var link = $(this).attr("link");
		$(this).hide();
		page = link;
		$.ajax({
			url:page,
			success:function(result){
				alert("卖家已秒发，刷新当前页面，即可确认收货");
			}
		});
	});
});
</script>
<div class="boughtDiv">
	<div class="orderType">
		<div class="selectedOrderType"><a href="#" orderStatus="all">所有订单</a></div>
		<div><a href="#nowhere" orderStatus="waitPay">待付款</a></div>
        <div><a href="#nowhere" orderStatus="waitDelivery">待发货</a></div>
        <div><a href="#nowhere" orderStatus="waitConfirm">待收货</a></div>
        <div><a class="noRightborder" href="#nowhere" orderStatus="waitReview">待评价</a></div>
        <div class="orderTypeLastOne">
        </div>
	</div>
	<div class="orderListTitle">
		<table class="orderListTitleTable">
			<tbody>
				<tr>
					<td>宝贝</td>
					<td width="100px">单价</td>
					<td width="100px">数量</td>
					<td width="130px">实付款</td>
					<td width="100px">交易操作</td>
				</tr>
			</tbody>
		</table>
	</div>
	
	<!-- 产品列表 -->
	<div class="orderListItem">
		<c:forEach items="${orders}" var="o">
			<table oid="${o.id}" orderStatus="${o.status}" class="orderListItemTable">
				<tbody>
					<tr class="orderListItemFirstTR">
						<td colspan="2">
							<b><fmt:formatDate value="${o.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/> </b>
							<span>订单号: ${o.orderCode}</span>
						</td>
						<td colspan="2"><img width="13px" src="./img/site/orderItemTmall.png" />天猫商城</td>
						<td colspan="1">
							<a href="#" class="wangwanglink">
								<div class="orderItemWangWangGif"></div>
							</a>
						</td>
						<td class="orderItemDeleteTD">
							<a href="#" oid="${o.id}" class="deleteOrderLink">
								<span class="orderListItemDelete glyphicon glyphicon-trash"></span>
							</a>
						</td>
					</tr>
					
					<c:forEach items="${o.orderItems}" var="oi" varStatus="st">
						<tr class="orderItemProductInfoPartTR">
							<td width="100px" class="orderItemProductInfoPartTD">
								<img width="80" height="80" src="./img/productSingle_middle/${oi.product.firstProductImage.id}.jpg">
							</td>
							<td class="orderItemProductInfoPartTD">
								<div class="orderListItemProductLinkOutDiv">
									<a href="foreproduct?product.id=${oi.product.id}">${oi.product.name}</a>
									<div class="orderListItemProductLinkInnerDiv">
										<img title="支持信用卡支付" src="./img/site/creditcard.png">
		                                <img title="消费者保障服务,承诺7天退货" src="./img/site/7day.png">
		                                <img title="消费者保障服务,承诺如实描述" src="./img/site/promise.png"> 		
									</div>
								</div>
							</td>
							<td width="100px" class="orderItemProductInfoPartTD">
								<div class="orderListItemProductOriginalPrice">￥<fmt:formatNumber type="number" value="${oi.product.originalPrice}" minFractionDigits="2" /></div>
		                        <div class="orderListItemProductPrice">￥<fmt:formatNumber type="number" value="${oi.product.promotePrice}" minFractionDigits="2" /></div>
							</td>
							
							<c:if test="${st.count==1}">
								<td width="100px" valign="top" class="orderListItemNumberTD orderItemOrderInfoPartTD" rowspan="${fn:length(o.orderItems)}">
			                        <span class="orderListItemNumber">${o.totalNumber}</span>
			                    </td>
			                    <td width="120px" valign="top" class="orderListItemProductRealPriceTD orderItemOrderInfoPartTD" rowspan="${fn:length(o.orderItems)}">
			                        <div class="orderListItemProductRealPrice">￥<fmt:formatNumber type="number" value="${o.total}" minFractionDigits="2" maxFractionDigits="2"/></div>
			                        <div class="orderListItemPriceWithTransport">(含运费：￥0.00)</div>
			                    </td>
			                    <td width="100px" valign="top" class="orderListItemButtonTD orderItemOrderInfoPartTD" rowspan="${fn:length(o.orderItems)}">
			                    	<c:if test="${o.status=='waitConfirm'}">
				                        <a href="foreconfirmPay?order.id=${o.id}">
				                            <button class="orderListItemConfirm">确认收货</button>
				                        </a>
			                        </c:if>
			                    	<c:if test="${o.status=='waitPay'}">
				                        <a href="foreaalipay?order.id=${o.id}&total=${o.total}">
				                            <button class="orderListItemConfirm">付款</button>
				                        </a>
			                        </c:if>
			                        <c:if test="${o.status=='waitDelivery'}">
			                        	<span>待发货</span>
			                        	<button class="btn btn-info btn-sm ask2delivery" link="admin_order_delivery?order.id=${o.id}">催卖家发货</button>
			                        </c:if>
			                        <c:if test="${o.status=='waitReview'}">
			                        	<a href="forereview?order.id=${o.id}">
			                        		<button class="orderListItemReview">评价</button>
			                        	</a>
			                        </c:if>
			                    </td> 
		                    </c:if>      
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</c:forEach>
	</div>
</div>
</html>